<?php
require 'page.class.php';
session_start();

$username=$_SESSION['username'];
$connetc=mysql_connect("localhost","root","");
mysql_select_db("shenji",$connetc);
mysql_query("set names utf8");
$sql4="select * from user where username='$username'";

$result4=mysql_query($sql4);
$row4=mysql_num_rows($result4);


if($row4==0){
	echo "<script>alert('用户不存在，请重新登录！');top.location.href='./login.php'</script>";
}else{


$sql2="select count(*) as amount from type";
$result2=mysql_query($sql2);
$row2=mysql_fetch_array($result2);
$count=$row2['amount'];//总条数
$pagesize=10;//每页显示的条数
if($count%$pagesize){
	$page=ceil($count/$pagesize);
}else{
	$page=$count/$pagesize;
}
if(isset($_GET['currentpage'])){
	$currentpage=intval($_GET['currentpage']);
}else{
	$currentpage=1;
}
$start=($currentpage-1)*$pagesize;
$sql="select * from type order by typeid desc limit $start,$pagesize";
$result = mysql_query($sql);
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-1.6.3.min.js"></script>
<style>
      .tip{
		  width:600px;
		  height:350px;
	  }

</style>
<script type="text/javascript">
$(document).ready(function(){
  $(".click").click(function(){
     $(".tip").fadeIn(200);
  });
  
  $(".tiptop a").click(function(){
     $(".tip").fadeOut(200);
  });
}); 
</script>

</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">项目配置</a></li>
    <li><a href="#">项目列表</a></li>
    </ul>
    </div>
	
    <div class="rightinfo">
    
    <div class="tools">
    	<ul class="toolbar">
        <li><a href="insert_xiangmu.php"><span><img src="images/t01.png" /></span>添加</a></li>
        <li onclick="deletebatch()"><span><img src="images/t03.png"/></span>删除</li>
        </ul>
    </div>
	
    <table class="tablelist">
    	<thead>
    	<tr>
        <th><input  type="checkbox" name="checkbox" onclick="selectAll(this)"/></th>
        <th>项目名称</th>
        <th>英文名称</th>
        <th>基本操作</th>
        </tr>
        </thead>
        <tbody>
		<?php
		while($row=mysql_fetch_array($result)){
		?>
		<tr>
        <td><input  type="checkbox" name="son_checkbox" value="<?php echo $row['typeid'];?>"/></td>
        <td><?php echo $row['name'];?></td>
        <td><?php echo $row['ename'];?></td>
        <td><a  onclick="ck('<?php echo $row['typeid'];?>');" class="tablelink" href="#">修改</a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="delete_xiangmu.php?typeid=<?php echo $row['typeid'];?>" onclick="if(confirm('确认删除？')==false) return false;" class="tablelink"> 删除</a></td>
        </tr> 
		<?php
	     }	
		?>
        </tbody>
    </table>
	
    <div class="pagin">
    	<?php 
    		pagelinks();
    	?>
    </div>
	
    <div class="tip">
	  <div class="tiptop"><span>项目栏目</span><a id="refresh"></a></div>
      <div class="formbody">
      <form method="post" action="update_xiangmu.php">
	  <input size="20" type="hidden" name="id" id="id">
      <ul class="forminfo">
      <li><label>项目名称</label><input  id="xmname" name="xmname" type="text" onblur="shouzhong_name();" class="dfinput" /><i id="yz_name" style="display:none;color:#f00;">名称格式不正确，由中文且长度为2~5个字符</i></li>
	  <li><label>英文名称</label><input  id="ename" name="ename" type="text" onblur="shouzhong_ename();" class="dfinput" /><i id="yz_beizhu" style="display:none;color:#f00;">英文名称格式不正确(最好为其中文对应的名称)</i></li>
	  <li><label>处理候选码</label>
	  		<input type="radio" id="manage"name="manage"value='0'class="manage1">开启
	  		<input type="radio" id="manage"name="manage"value='1'class="manage2">关闭
	  		
	  </li>
      <li><label>&nbsp;</label><input name="submit" type="submit" class="btn" value="确认保存"/></li>
      </ul>
	  </form>
      </div>
      <!--
	  <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" />&nbsp;
      <input name="" type="button"  class="cancel" value="取消" />
      </div>
	  -->
    </div>
	
    </div>
    
    <script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');
	function ck(id){
		$.post("select_xiangmu_id.php",{typeid:id},function(data){
			   $("#id").val(data['typeid']);
			   $("#xmname").val(data['name']);
			   $("#ename").val(data['ename']);
			   //$("#manage").val(data['manage']);	
			   var type=data['manage'];
			   if(type==0){
			   	$(".manage1").attr("checked",'checked');
			   }else{
			   	$(".manage2").attr("checked",'checked');
			   }
			   $(".tip").fadeIn(200);
		},"json")		
	}

	function selectAll(objs){
	    obj=document.getElementsByName('son_checkbox');
		for(var i=0;i<obj.length;i++){
			if(objs.checked){
				obj[i].checked=true;
			}else{
				obj[i].checked=false;
			}
			
		}
	}
	
	function deletebatch(){
	      obj=document.getElementsByName('son_checkbox');
		  var arrayid=new Array();
		  for(var i=0;i<obj.length;i++){
			  if(obj[i].checked){
				 var value=obj[i].value;
				 arrayid.push(value);
			  }
			  
		  }
		  
		  if(arrayid.length==0){
			  alert("请选择需要删除的项目");
		  }else{
			  
			  if(confirm("确定要删除所选择的项目吗")){
				  
				  $.post('delete_xiangmu.php',{arrayid:arrayid},function(data){
				  window.location.href="select_xiangmu.php";
			    });
				  
			  }else{
				  return false;
			  }
			  
		  }
		  
	}
	
   function shouzhong_name(){
	var xmname=/^[\u4e00-\u9fa5]{2,5}$/;
	if(xmname.test($('#xmname').val())){
		$("#yz_name").hide();
	}else{
		$("#yz_name").show();
	}
	}
   	function shouzhong_ename(){
	var ename=/^[a-zA-Z]{1,20}$/;
	if(ename.test($('#ename').val())){
		$("#yz_beizhu").hide();
	}else{
		$("#yz_beizhu").show();
	}
	}
$(function(){
		$('.btn').bind('click',function(event){
			var xmname=/^[\u4e00-\u9fa5]{2,5}$/;
			if(xmname.test($('#xmname').val())){
				$("#yz_name").hide();	
			}else{
				$("#yz_name").show();	
				return false;
			}			
		})
	})
		$(function(){
		$('.btn').bind('click',function(event){
			var ename=/^[a-zA-Z]{1,20}$/;
			if(ename.test($('#ename').val())){
				$("#yz_beizhu").hide();				
			}else{
				$("#yz_beizhu").show();		
				return false;
			}			
		})
	})
$(function(){

	$("#xmname").focus(function(){
		$("#yz_name").hide();
	})
	$("#ename").focus(function(){
		$("#yz_beizhu").hide();
	})
})
$(function(){
	$("#refresh").click(function(){
		location.reload();
	})
})
	</script>

</body>

</html>
